<?php // Request webpage

// Load Helpers
$this->load->helper('url');
// Load Models
$this->load->model('Mtopics');
$this->load->model('Mposts');
$this->load->model('Mcurl');
$curl = new Mcurl();
$curl->setCookie(uniqid('dad') . '.txt');

$model_topic = new Mtopics();
$model_post  = new Mposts();
$data = $model_topic->listTopics();

foreach ($data as $topic) {
	$title = $curl->getStr($topic->content, 'rel="bookmark" title="', '"');
	$slug = $curl->getStr($topic->content, '<a itemprop="url" href="', '"');
	$publish = $curl->getStr($topic->content, 'class="entry-date updated" datetime="', '"');
	if (strpos($topic->content, 'class="entry-thumb" src="')) {
		$image = $curl->getStr($topic->content, 'class="entry-thumb" src="', '"');
	}
	$description = $curl->getStr($topic->content, '<p>', '</p>');
	$content = trim($curl->getStr($topic->content, '<ul class="td-category">', '</ul>'));

	$id = $model_post->createPost(array(
		'title' => $title,
		'slug' => $slug,
		'description' => $description,
		'content' => $content,
		'publish' => $publish,
		'image' => @$image,
		'status' => 'P'
	));

	if ($id) $model_topic->updateStatus($topic->id);
}

redirect('/update/content');
?>